Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure sequential execution of connection state callbacks #656

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Mar 13, 2024

Ice update connection state callbacks need to happen sequentially otherwise a later callback could overwrite a newer callback.

Fixes: #624

@sukunrt sukunrt changed the title Wait for update callbacks to finish Wait for update state callbacks to finish Mar 13, 2024
Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.89%. Comparing base (77cc354) to head (59cc806).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #656      +/-   ##
==========================================
+ Coverage   78.84%   78.89%   +0.04%     
==========================================
  Files          42       42              
  Lines        4444     4454      +10     
==========================================
+ Hits         3504     3514      +10     
  Misses        722      722              
  Partials      218      218              
Flag Coverage Δ
go 78.89% <100.00%> (+0.04%) ⬆️
wasm 23.57% <90.90%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

agent_handlers.go Outdated Show resolved Hide resolved
agent.go Outdated
@@ -278,7 +278,7 @@ func NewAgent(config *AgentConfig) (*Agent, error) { //nolint:gocognit

a := &Agent{
chanTask: make(chan task),
chanState: make(chan ConnectionState),
chanState: make(chan ConnectionState, 4),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 4 ?
Won't this deadlock if we get unlucky and there is 5 events queued up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need this to close the agent correctly. The current behaviour allows agent closing in the callback which with a channel capacity of 0 would lead to deadlock.

I will see what the right way to handle this is.

Copy link
Member Author

@sukunrt sukunrt Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that we can go Connected to Disconnected to Connected many many times, I don't think a limit to the channel can work. Especially considering that we don't want to block the go routine sending to chanState. So I've introduced a queue here which runs the callbacks in a separate goroutine

@sukunrt sukunrt marked this pull request as draft March 14, 2024 13:39
@sukunrt sukunrt changed the title Wait for update state callbacks to finish Ensure sequential execution of connection state callbacks Mar 15, 2024
@sukunrt sukunrt force-pushed the update-state-seq branch 3 times, most recently from a069da8 to dbc776c Compare March 15, 2024 15:07
@sukunrt sukunrt marked this pull request as ready for review March 15, 2024 15:08
@sukunrt sukunrt requested review from Jorropo and Sean-Der and removed request for Jorropo March 15, 2024 15:08
Before we launched a goroutine to announce every ConnectionState change
to users. These could then be sent to the user out of order.

This commit adds a connectionStateNotifier. The connectionStateNotifier
delivers them sequentially to the user.

Resolves #624
@Sean-Der Sean-Der merged commit 67cc918 into master Mar 20, 2024
14 checks passed
@Sean-Der Sean-Der deleted the update-state-seq branch March 20, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ConnectionState changes may be reported incorrectly
3 participants